package cn.dansj.common.mail.bean;

import cn.dansj.common.utils.enums.GlobalEnv;
import cn.dansj.common.utils.json.JSONObject;
import cn.dansj.common.utils.transfer.DefaultMethods;
import cn.dansj.common.utils.transfer.Transformation;

import java.io.Serializable;

/**
 * 邮件服务配置信息
 */
public class MailConfigure extends DefaultMethods implements Serializable {
    private static final long serialVersionUID = GlobalEnv.SerialVersionUID;
    private String host;
    private int port = 25;
    private String username;
    private String password;
    private String encoding = "UTF-8";
    private boolean auth = true;
    private boolean ssl = false;
    private boolean debug = false;

    public MailConfigure() {
    }

    /*传入JSON串自动查找*/
    public MailConfigure(JSONObject configure) {
        this.host = Transformation.nvl(configure.getString("host"), configure.getString("server"), configure.getString("address"));
        this.port = configure.getIntValue("port") == 0 ? 25 : configure.getIntValue("port");
        this.username = Transformation.nvl(configure.getString("username"), "");
        this.password = configure.getString("password");
        this.encoding = Transformation.nvl(configure.getString("encoding"), "UTF-8");
        this.auth = Transformation.nvl(configure.getBoolean("useAuth"), configure.getBoolean("auth"), true);
        this.ssl = Transformation.nvl(configure.getBoolean("isSSL"), configure.getBoolean("userSSL"), configure.getBoolean("SSL"), false);
        this.debug = Transformation.nvl(configure.getBoolean("debug"), false);
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEncoding() {
        return encoding;
    }

    public void setEncoding(String encoding) {
        this.encoding = encoding;
    }

    public boolean isAuth() {
        return auth;
    }

    public void setAuth(boolean auth) {
        this.auth = auth;
    }

    public boolean isDebug() {
        return debug;
    }

    public boolean isSsl() {
        return ssl;
    }

    public void setSsl(boolean ssl) {
        this.ssl = ssl;
    }

    public void setDebug(boolean debug) {
        this.debug = debug;
    }
}
